import java.util.Vector;
import java.io.BufferedReader;

class SymbolManager {
    Vector<String> symbols = new Vector<String>();
    
    public SymbolManager(BufferedReader reader) throws Exception {
        reader.readLine();  //Existing symbols:
        int num = Integer.parseInt(reader.readLine().trim());
        reader.readLine();  //Symbols:
        for(int i = 0; i < num; i++) {
            String[] parts = reader.readLine().trim().split("[ \t]+");
            symbols.add(parts[1]);
        }
    }
    
    int getId(String symbol) {
        for(int i=0;i<symbols.size();i++)
            if(symbols.elementAt(i).equals(symbol))
                return i + 1;
        symbols.add(symbol);
        return symbols.size();
    }
    
    public String asString() {
        String ret = "Existing symbols:\n" + symbols.size() + "\nSymbols:";
        for(int i = 0; i < symbols.size(); i++)
            ret = ret + "\n" + (i + 1) + "\t" + symbols.elementAt(i);
        return ret;
    }
}
